package com.example.controller.impl;

import com.example.controller.UserController;
import com.example.dto.ResultDTO;
import com.example.dto.UserDTO;
import com.example.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@Slf4j
public class UserControllerImpl implements UserController {

    @Override
    public String index() {
        log.info("index接口");
        return "index";
    }

    @Override
    public ResultDTO<List<UserDTO>> query() {
        log.info("查询成功:{}", DateUtil.getNowDateStr(new Date(), DateUtil.YYYY_MM_DD_HH_MM_SS));
        List<UserDTO> list = new ArrayList<>();
        list.add(new UserDTO(1, "SZ", "深圳", new Date()));
        list.add(new UserDTO(2, "BJ", "北京", null));
        list.add(new UserDTO(3, "SH", "上海", null));
        list.add(new UserDTO(4, null, null, new Date()));
        return new ResultDTO<>(200, "查询成功", list);
    }

    @Override
    public ResultDTO<String> add(UserDTO userDTO) {
        log.info("新增成功:{}", userDTO);
        return new ResultDTO<>(200, "新增成功","新增成功");
    }

    @Override
    public ResultDTO<String> update(UserDTO userDTO, String id) {
        log.info("更新成功userDTO:{},id:{}", userDTO, id);
        return new ResultDTO<>(200, "更新成功","更新成功");
    }

    @Override
    public ResultDTO<String> delete(String id) {
        log.info("删除成功id:{}", id);
        return new ResultDTO<>(200, "删除成功","删除成功");
    }
}
